#include "MineDesign3D/IReplaceUI.hpp"
#include <AntTweakBar.h>
#include "MineDesign3D/GetBlockTwEnum.hpp"
#include "MineDesign3D/BoxelManager.hpp"
#include "MineDesign3D/UIManager.hpp"
namespace MineDesign3D{
class ReplaceUI : public IReplaceUI
{
public:
	virtual void Init()
	{
		if(TwGetBarByName("Replace"))
		{
			TwDefine("Replace visible=true");
		}
		else
		{
			TwBar* pReplaceBar = TwNewBar("Replace");

			TwDefine("Replace position='300 100' size='200 120'");

			TwType EnumType = GetBlockTwEnum();
			TwAddVarRW(pReplaceBar,"from",EnumType,&oldID,"");
			TwAddVarRW(pReplaceBar,"to",EnumType,&newID,"");

			struct Replace
			{
				static void TW_CALL Do(void*)
				{
					g_pBoxelManager()->replace(oldID,newID);
					g_pUIManager()->replaceExit();
				}
				static void TW_CALL Canncel(void*)
				{
					g_pUIManager()->replaceCanncel();
				}
			};

			TwAddButton(pReplaceBar,"Replace!",Replace::Do,0,"");
			TwAddButton(pReplaceBar,"Canncel",Replace::Canncel,0,"");
		}
	}
	virtual void Fin()
	{
		TwDefine("Replace visible=false");
	}
	static int oldID;
	static int newID;
};
int ReplaceUI::oldID = 0;
int ReplaceUI::newID = 0;

IReplaceUI::ptr CreateReplaceUI()
{
	return IReplaceUI::ptr(new ReplaceUI());
}
}//MineDesign3D
